# 自定义gdb命令 Twine_union_Child_print:  打印单个宏名字或单个宏值

#{ 命令 Twine_union_Child_print 定义开始
define Twine_union_Child_print


#假while循环 开始
set var $loop_cond = 1
while $loop_cond

set $_Twine_union_Child=$arg0
set $_NodeKind=$arg1
set $_owner=$arg2

if $_NodeKind == llvm::Twine::TwineKind
	printf "%s.twine:%x_ptr \n",$_owner,$_Twine_union_Child.twine
end

if $_NodeKind == llvm::Twine::CStringKind
	printf "%s.cString:%s \n",$_owner,$_Twine_union_Child.cString
end

if $_NodeKind == llvm::Twine::StdStringKind
	printf "%s.stdString:%s \n",$_owner,$_Twine_union_Child.stdString->c_str()
end


if $_NodeKind == llvm::Twine::PtrAndLengthKind
	# printf "%s.ptrAndLength.ptr:%x, %s.ptrAndLength.length:%d \n",$_owner,$_Twine_union_Child.ptrAndLength.ptr, $_owner,$_Twine_union_Child.ptrAndLength.length
	# python print( gdb.parse_and_eval("Name.LHS.ptrAndLength.ptr").string("ascii","ascii",gdb.parse_and_eval("Name.LHS.ptrAndLength.length").cast(gdb.lookup_type("int"))) )
	# printf "%s.ptrAndLength.length:%d \n",$_owner,$_Twine_union_Child.ptrAndLength.length

	if $_Twine_union_Child.ptrAndLength.length > 0
		printf "%s.ptrAndLength.length:%d ",$_owner,$_Twine_union_Child.ptrAndLength.length
		python print( gdb.parse_and_eval("$_Twine_union_Child.ptrAndLength.ptr").string("ascii","ascii",gdb.parse_and_eval("$_Twine_union_Child.ptrAndLength.length").cast(gdb.lookup_type("int"))) )
	else
		printf "%s.ptrAndLength.length:%d .\n",$_owner,$_Twine_union_Child.ptrAndLength.length
	end
	#if结束

end

if $_NodeKind == llvm::Twine::FormatvObjectKind
	printf "%s.formatvObject:0x%x_ptr \n",$_owner,$_Twine_union_Child.formatvObject
end

if $_NodeKind == llvm::Twine::CharKind
	printf "%s.character:%c \n",$_owner,$_Twine_union_Child.character
end

# https://cplusplus.com/reference/cstdio/printf/

if $_NodeKind == llvm::Twine::DecUIKind
	printf "%s.decUI:%u \n",$_owner,$_Twine_union_Child.decUI
end

if $_NodeKind == llvm::Twine::DecIKind
	printf "%s.decI:%d \n",$_owner,$_Twine_union_Child.decI
end

if $_NodeKind == llvm::Twine::DecULKind
	printf "%s.decUL:0x%x_ptr \n",$_owner,$_Twine_union_Child.decUL
end

if $_NodeKind == llvm::Twine::DecLKind
	printf "%s.decL:0x%x_ptr \n",$_owner,$_Twine_union_Child.decL
end

if $_NodeKind == llvm::Twine::DecULLKind
	printf "%s.decULL:0x%x_ptr \n",$_owner,$_Twine_union_Child.decULL
end

if $_NodeKind == llvm::Twine::DecLLKind
	printf "%s.decLL:0x%x_ptr \n",$_owner,$_Twine_union_Child.decLL
end

if $_NodeKind == llvm::Twine::UHexKind
	printf "%s.uHex:0x%x_ptr \n",$_owner,$_Twine_union_Child.uHex
end

# if xxx
# loop_break
#提前退出 本命令过程 用 loop_break
# end

# loop_break
#退出假while循环

set var $loop_cond = 0
end
#假while循环 结束

end
#命令 Twine_union_Child_print 定义结束 }
